package com.briup.srms.sms.web.controller;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.srms.sms.bean.Channel;
import com.briup.srms.sms.bean.extend.ChannelExtend;
import com.briup.srms.sms.service.IChannelService;
import com.jacky.base.utils.Message;
import com.jacky.base.utils.MessageUtil;
import com.jacky.base.utils.PageVM;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @program: 杰普基础管理系统
 * @description: 渠道管理的控制器类
 * @author: charles
 * @create: 2020-11-14 15:09
 **/
@Api(description="渠道相关接口")
@Validated
@RestController
@RequestMapping("/channel")
public class ChannelController {
	@Autowired
	private IChannelService channelService;

	@ApiOperation(value = "查询渠道树")
    @GetMapping("queryTree")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "当前页", required = true, paramType = "query"),
		@ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),
		@ApiImplicitParam(name = "name", value = "渠道名称", paramType = "query")
	})
    public Message queryTree(@NotNull Integer page,@NotNull Integer pageSize,String name){
		PageVM<ChannelExtend> list = channelService.queryTree(page,pageSize,name);
        return MessageUtil.success(list);
    }

	@ApiOperation(value = "保存或更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Channel channel){
		channelService.saveOrUpdate(channel);
        return MessageUtil.success("操作成功");
    }

	@ApiOperation(value = "根据ID删除")
    @GetMapping("deleteById")
    public Message deleteById(@NotNull long id){
		channelService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

}
